<?php
include_once 'app/until/GFW_database.php';

class Db_Publish extends Model_Db_Core  {

	protected  $con = null;
	protected  $publish = null;

	function __construct(){
		//
	}

	public function GetLastPublish($user_id, $limit = 25, $offset = 0){
		$sql = 'SELECT DISTINCT(publish.user_id), publish.id, publish.text, publish.datum, user.username, user.bild_50
						FROM freunde, publish, user 
							where (freunde.user_id_1 = '.$user_id.' or freunde.user_id_2 = '.$user_id.') and (freunde.user_id_1 = publish.user_id or freunde.user_id_2 = publish.user_id) and publish.user_id = user.id 
								ORDER BY `publish`.`datum` DESC LIMIT '.$offset.' ,'.$limit;
		
		parent::setSqlManuel($sql);
	    $this->publish = parent::result(1);
	    		
		return $this->publish;
	}
	public function Publish($user_id, $text){
	    parent::setInsert(__CLASS__);
		 	 	
		$this->value['user_id'] = $user_id;
		$this->value['text'] = $text;
		$this->value['datum'] = "NOW()";
		
	    $status = $this->writeToDb();
	   
	    return $status;
	}
	
}

?>